package com.example.demo03_mvm;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.demo03_mvm.adapter.FragAdapter;
import com.example.demo03_mvm.adapter.TypesAdapter;
import com.example.demo03_mvm.databinding.ActivityMainBinding;
import com.example.demo03_mvm.model.GoodsTypeEntity;
import com.example.demo03_mvm.utils.ACache;
import com.example.demo03_mvm.utils.MyViewPager;
import com.example.demo03_mvm.view.BaseActivity;
import com.example.demo03_mvm.view.CartFragment;
import com.example.demo03_mvm.view.HomeFragment;
import com.example.demo03_mvm.view.MeFragment;
import com.example.demo03_mvm.view.TypeFragment;
import com.example.demo03_mvm.viewmodel.MainViewModel;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

import java.util.ArrayList;
@Route(path = "/app/MainActivity")
public class MainActivity extends BaseActivity<MainViewModel,ActivityMainBinding> {

    BottomNavigationView nav;
    MyViewPager vp;

//    @Autowired
//    int k;
    @Override
    protected int inflateLayout() {
        return R.layout.activity_main;
    }

    public void initData(){
        ArrayList<Fragment> list = new ArrayList<>();
        list.add(HomeFragment.newInstance());
        list.add(TypeFragment.newInstance());
        list.add(CartFragment.newInstance());
        list.add(MeFragment.newInstance());
        FragAdapter fragAdapter = new FragAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, list);
        vp.setAdapter(fragAdapter);
        vp.setOffscreenPageLimit(3);

        nav.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.item_hone:
                        vp.setCurrentItem(0);
                        break;
                    case R.id.item_type:
                        vp.setCurrentItem(1);
                        break;
                    case R.id.item_car:
                        vp.setCurrentItem(2);
                        break;
                    case R.id.item_me:
                        vp.setCurrentItem(3);
                        break;
                }
                return true;
            }
        });

        /*ACache aCache = ACache.get(App.getContext());
        aCache.put("user","aa",30);*/

    }

    /*@Override
    protected void onResume() {
        super.onResume();
        Log.i("===","onResume");

            //vp.setCurrentItem(k);

        *//*ACache aCache = ACache.get(App.getContext());
        String user = aCache.getAsString("user");
        if(user!=null){
            Log.i("===",user);
        }else{
            Log.i("===","值已失效");
        }*//*

    }*/

    public void initView(){
        nav=db.nav;
        vp=db.vp;
        //ARouter.getInstance().inject(this);
    }
}